Week 2 - Blink Using OS
app_hooks.c
1 /*
2 *********************************************************************************************************
3 * EXAMPLE CODE
4 *
5 * (c) Copyright 2012; Micrium, Inc.; Weston, FL
6 *
7 * All rights reserved. Protected by international copyright laws.
8 * Knowledge of the source code may NOT be used to develop a similar product.
9 * Please help us continue to provide the Embedded community with the finest
10 * software available. Your honesty is greatly appreciated.
11 *********************************************************************************************************
12 */
13 
14 /*
15 *********************************************************************************************************
16 *
17 * uC/OS-II
18 * Application Hooks
19 *
20 * Filename : app_hooks.c
21 * Version : V1.00
22 * Programmer(s) : FT
23 *********************************************************************************************************
24 */
25 
26 /*
27 *********************************************************************************************************
28 * INCLUDE FILES
29 *********************************************************************************************************
30 */
31 
32 #include <os.h>
33 
34 /*
35 *********************************************************************************************************
36 * EXTERN GLOBAL VARIABLES
37 *********************************************************************************************************
38 */
39 
40 
41 /*
42 *********************************************************************************************************
43 * LOCAL CONSTANTS
44 *********************************************************************************************************
45 */
46 
47 
48 /*
49 *********************************************************************************************************
50 * LOCAL DATA TYPES
51 *********************************************************************************************************
52 */
53 
54 /*
55 *********************************************************************************************************
56 * LOCAL TABLES
57 *********************************************************************************************************
58 */
59 
60 
61 /*
62 *********************************************************************************************************
63 * LOCAL GLOBAL VARIABLES
64 *********************************************************************************************************
65 */
66 
67 
68 /*
69 *********************************************************************************************************
70 * LOCAL FUNCTION PROTOTYPES
71 *********************************************************************************************************
72 */
73 
74 
75 
76 /*
77 **********************************************************************************************************
78 **********************************************************************************************************
79 ** GLOBAL FUNCTIONS
80 **********************************************************************************************************
81 **********************************************************************************************************
82 */
83 
84 /*
85 *********************************************************************************************************
86 *********************************************************************************************************
87 ** uC/OS-II APP HOOKS
88 *********************************************************************************************************
89 *********************************************************************************************************
90 */
91 
92 #if (OS_APP_HOOKS_EN > 0)
93 
94 /*
95 *********************************************************************************************************
96 * TASK CREATION HOOK (APPLICATION)
97 *
98 * Description : This function is called when a task is created.
99 *
100 * Argument(s) : ptcb is a pointer to the task control block of the task being created.
101 *
102 * Note(s) : (1) Interrupts are disabled during this call.
103 *********************************************************************************************************
104 */
105 
106 void App_TaskCreateHook (OS_TCB *ptcb)
107 {
108 #if (APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && (OS_PROBE_HOOKS_EN > 0)
109  OSProbe_TaskCreateHook(ptcb);
110 #endif
111 }
112 
113 /*
114 *********************************************************************************************************
115 * TASK DELETION HOOK (APPLICATION)
116 *
117 * Description : This function is called when a task is deleted.
118 *
119 * Argument(s) : ptcb is a pointer to the task control block of the task being deleted.
120 *
121 * Note(s) : (1) Interrupts are disabled during this call.
122 *********************************************************************************************************
123 */
124 
125 void App_TaskDelHook (OS_TCB *ptcb)
126 {
127  (void)ptcb;
128 }
129 
130 /*
131 *********************************************************************************************************
132 * IDLE TASK HOOK (APPLICATION)
133 *
134 * Description : This function is called by OSTaskIdleHook(), which is called by the idle task. This hook
135 * has been added to allow you to do such things as STOP the CPU to conserve power.
136 *
137 * Argument(s) : none.
138 *
139 * Note(s) : (1) Interrupts are enabled during this call.
140 *********************************************************************************************************
141 */
142 
143 #if OS_VERSION >= 25100
144 void App_TaskIdleHook (void)
145 {
146 }
147 #endif
148 
149 /*
150 *********************************************************************************************************
151 * STATISTIC TASK HOOK (APPLICATION)
152 *
153 * Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
154 * statistics task. This allows your application to add functionality to the statistics task.
155 *
156 * Argument(s) : none.
157 *********************************************************************************************************
158 */
159 
160 void App_TaskStatHook (void)
161 {
162 }
163 
164 /*
165 *********************************************************************************************************
166 * TASK RETURN HOOK (APPLICATION)
167 *
168 * Description: This function is called if a task accidentally returns. In other words, a task should
169 * either be an infinite loop or delete itself when done.
170 *
171 * Arguments : ptcb is a pointer to the task control block of the task that is returning.
172 *
173 * Note(s) : none
174 *********************************************************************************************************
175 */
176 
177 
178 #if OS_VERSION >= 28900
179 void App_TaskReturnHook (OS_TCB *ptcb)
180 {
181  (void)ptcb;
182 }
183 #endif
184 
185 /*
186 *********************************************************************************************************
187 * TASK SWITCH HOOK (APPLICATION)
188 *
189 * Description : This function is called when a task switch is performed. This allows you to perform other
190 * operations during a context switch.
191 *
192 * Argument(s) : none.
193 *
194 * Note(s) : (1) Interrupts are disabled during this call.
195 *
196 * (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
197 * will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
198 * task being switched out (i.e. the preempted task).
199 *********************************************************************************************************
200 */
201 
202 #if OS_TASK_SW_HOOK_EN > 0
203 void App_TaskSwHook (void)
204 {
205 #if (APP_CFG_PROBE_OS_PLUGIN_EN > 0) && (OS_PROBE_HOOKS_EN > 0)
206  OSProbe_TaskSwHook();
207 #endif
208 }
209 #endif
210 
211 /*
212 *********************************************************************************************************
213 * OS_TCBInit() HOOK (APPLICATION)
214 *
215 * Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
216 * up most of the TCB.
217 *
218 * Argument(s) : ptcb is a pointer to the TCB of the task being created.
219 *
220 * Note(s) : (1) Interrupts may or may not be ENABLED during this call.
221 *********************************************************************************************************
222 */
223 
224 #if OS_VERSION >= 20400
225 void App_TCBInitHook (OS_TCB *ptcb)
226 {
227  (void)ptcb;
228 }
229 #endif
230 
231 /*
232 *********************************************************************************************************
233 * TICK HOOK (APPLICATION)
234 *
235 * Description : This function is called every tick.
236 *
237 * Argument(s) : none.
238 *
239 * Note(s) : (1) Interrupts may or may not be ENABLED during this call.
240 *********************************************************************************************************
241 */
242 
243 #if OS_TIME_TICK_HOOK_EN > 0
244 void App_TimeTickHook (void)
245 {
246 #if (APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && (OS_PROBE_HOOKS_EN > 0)
247  OSProbe_TickHook();
248 #endif
249 }
250 #endif
251 #endif